﻿using System;
using System.Text;
using System.Collections;
using System.Xml;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Threading;

using Telerik.WebControls;
using UFSoft.UBF.UI.WebControls;
using UFSoft.UBF.UI.Controls;
using UFSoft.UBF.Util.Log;
using UFSoft.UBF.Util.Globalization;

using UFSoft.UBF.UI.IView;
using UFSoft.UBF.UI.Engine;
using UFSoft.UBF.UI.MD.Runtime;
using UFSoft.UBF.UI.ActionProcess;
using UFSoft.UBF.UI.WebControls.ClientCallBack;
using System.Collections.Specialized;
using UFSoft.UBF.UI.FormProcess;
using UFSoft.UBF.UI.WebControlAdapter;



/***********************************************************************************************
 * Form ID: 
 * UIFactory Auto Generator 
 ***********************************************************************************************/
namespace DeliveryTORcvUIModel
{
    public partial class DeliveryTORcvUIFormWebPart
    {
        #region Custome eventBind
	
		 
				//OnOK1303_Click...
		private void OnOK1303_Click_Extend(object sender, EventArgs  e)
		{
            this.Model.ClearErrorMessage();
            this.DataBinding();
            this.DataCollect();
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
            if (this.Model.DeliveryLine.SelectRecords.Count == 0)
                throw new Exception("请选择行数据");
            UFIDA.U9.Cust.U9Demo.DeliveryBP.Proxy.CreateRcvProxy proxy = new UFIDA.U9.Cust.U9Demo.DeliveryBP.Proxy.CreateRcvProxy();
            proxy.DeliveryLineDTOList = new System.Collections.Generic.List<UFIDA.U9.Cust.U9Demo.DeliveryBP.DeliveryLineDTOData>();
            foreach(DeliveryLineRecord record in this.Model.DeliveryLine.SelectRecords)
            {
                if(record.ToQty > 0)
                {
                    UFIDA.U9.Cust.U9Demo.DeliveryBP.DeliveryLineDTOData dtoData = new UFIDA.U9.Cust.U9Demo.DeliveryBP.DeliveryLineDTOData();
                    dtoData.DeliveryLineID = record.ID;
                    dtoData.ToQty = record.ToQty??0;
                    decimal maxQty = record.Qty??0 - record.RcvQty??0 - record.ArrivedQty??0;
                    if (record.ToQty > maxQty)
                        throw new Exception("行" + record.DocLineNo + "转单数量不能大于最多转单数量" + System.Math.Round(maxQty, 2));
                    proxy.DeliveryLineDTOList.Add(dtoData);
                }
            }
            if (proxy.DeliveryLineDTOList.Count == 0)
                throw new Exception("请录入转单数量");
            long rcvID = proxy.Do();
            if (rcvID > 0)
            {
                NameValueCollection param = new NameValueCollection();
                param.Add("ID", rcvID.ToString());
                param.Add("RCV_Type", "PM6010");
                this.ShowAtlasModalDialog("91afbfb8-28af-44e6-9cf2-86d66ee16cb1", "收货单", "992", "504", this.TaskId.ToString(), param, false, false, false);
                this.CurrentState["DeliveryID"] = this.NameValues["DeliveryID"];
                this.CloseDialog(true);
            }
            else
                throw new Exception("生成收货单失败");
            OnOK1303_Click_DefaultImpl(sender,e);
		}	
		 
				//OnCancel474_Click...
		private void OnCancel474_Click_Extend(object sender, EventArgs  e)
		{
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.

            this.CloseDialog(false);
			OnCancel474_Click_DefaultImpl(sender,e);
		}

		
            
            

		#region 自定义数据初始化加载和数据收集
		private void OnLoadData_Extend(object sender)
		{	
			OnLoadData_DefaultImpl(sender);
		}
		private void OnDataCollect_Extend(object sender)
		{	
			OnDataCollect_DefaultImpl(sender);
		}
		#endregion  

        #region 自己扩展 Extended Event handler 
		public void AfterOnLoad()
		{
            
		}

        public void AfterCreateChildControls()
        {

            //开启个性化     
            UFIDA.U9.UI.PDHelper.PersonalizationHelper.SetPersonalizationEnable((BaseWebForm)this, true);

            ((UFWebDataGridAdapter)this.DataGrid0).AllowSelectAllPage = true;
        }
        
        public void AfterEventBind()
        {
        }
        
		public void BeforeUIModelBinding()
		{
            if (this.NameValues["DeliveryID"] != null)
            {
                string oPath = "  Delivery =" + this.NameValues["DeliveryID"] + "";
                oPath += " and (Qty - ArrivedQty - RcvQty) > 0";
                this.Model.DeliveryLine.Clear();
                this.Model.DeliveryLine.CurrentFilter.OPath = oPath;
                this.Action.CommonAction.Load(this.Model.DeliveryLine);
            }
            foreach(DeliveryLineRecord record in this.Model.DeliveryLine.Records)
            {
                record.ToQty = record.Qty - record.ArrivedQty - record.RcvQty;
            }
        }

		public void AfterUIModelBinding()
		{


		}


        #endregion
		
        #endregion
		
    }
}